/*
 * @file     g_systick.c
 * @brief    This file contains all the functions prototypes for the systick firmware library.
 *
 * Change Logs:
 * Date           Author             Version        Notes
 * 2021-05-28     xubo               V1.0.0         the first version
 */

/* Includes -----------------------------------------------------------------*/
#include "g_systick.h"
#include "g_sysctrl.h"


/* SysTick Reload value */
#define SYSTICK_RVR     ((volatile unsigned int *)0xE000E014)

#define CPU_MHZ     G_SYSCTRL_GetClocksFreq(MCU_FRE)
#define ONE_US      (CPU_MHZ/1000000)
#define ONE_MS      (CPU_MHZ/1000)


volatile tick SystickCount=0;

/* Exported functions -------------------------------------------------------*/
/**
 * @method G_SysTick_GetTick
 * @brief  get current systick_count
 * @param  None
 * @retval systick count
 */
tick G_SysTick_GetTick(void)
{
    return SystickCount;
}

/**
 * @method G_SysTick_IsTimeOut(ms)
 * @brief  Check whether func is timeout or not
 * @param  start_tick : Current tick number
 * @param  interval : timeout
 * @retval timeout or not
 */
G_Boolean G_SysTick_IsTimeOut(tick start_tick, int interval)
{
    start_tick = G_SysTick_GetTick() - start_tick;
    if (start_tick < 0)
        start_tick += TICK_MAX_VALUE;
    if ((start_tick*10) >= interval)
    {
        return TRUE;
    }
    else
    {
        return FALSE;
    }
}

/************************ (C) COPYRIGHT GKT *****END OF FILE****/
